﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
	xmlns:ic="http://schemas.microsoft.com/expression/2010/interactions"
	xmlns:local="clr-namespace:Alderamin"
	xmlns:AlderaminHelper="clr-namespace:Alderamin.Helper"
	mc:Ignorable="d"
	x:Class="Alderamin.MainView"
	Width="640" Height="480">
	<UserControl.Resources>
		<AlderaminHelper:WebproxyToStringConverter x:Key="WebproxyToStringConverter"/>
		<local:MainViewModel x:Key="MainViewModelDataSource" />
		
		<Storyboard x:Key="LoadedStoryboard">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ConfigPanel">
				<EasingDoubleKeyFrame KeyTime="0" Value="0">
					<EasingDoubleKeyFrame.EasingFunction>
						<CircleEase EasingMode="EaseOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
					<EasingDoubleKeyFrame.EasingFunction>
						<CircleEase EasingMode="EaseOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
			</DoubleAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="ConfigPanel">
				<EasingDoubleKeyFrame KeyTime="0" Value="50">
					<EasingDoubleKeyFrame.EasingFunction>
						<CircleEase EasingMode="EaseOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0">
					<EasingDoubleKeyFrame.EasingFunction>
						<CircleEase EasingMode="EaseOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
	</UserControl.Resources>
	<UserControl.Triggers>
		<EventTrigger RoutedEvent="FrameworkElement.Loaded">
			<BeginStoryboard Storyboard="{StaticResource LoadedStoryboard}"/>
		</EventTrigger>
	</UserControl.Triggers>

	<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource MainViewModelDataSource}}">
		<i:Interaction.Behaviors>
			<ic:DataStateBehavior Binding="{Binding IsProxyStopped, Mode=OneWay}" Value="True" TrueState="ProxyStoppedState" FalseState="ProxyStartedState"/>
		</i:Interaction.Behaviors>
		<VisualStateManager.VisualStateGroups>
			<VisualStateGroup x:Name="ProxyState">
				<VisualStateGroup.Transitions>
					<VisualTransition GeneratedDuration="0:0:0.5">
						<VisualTransition.GeneratedEasingFunction>
							<BackEase EasingMode="EaseIn"/>
						</VisualTransition.GeneratedEasingFunction>
					</VisualTransition>
				</VisualStateGroup.Transitions>
				<VisualState x:Name="ProxyStartedState">
					<Storyboard>
						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="ConfigPanel">
							<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
						</DoubleAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="StartButton">
							<DiscreteObjectKeyFrame KeyTime="0" Value="Stop"/>
						</ObjectAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="InfoPanel">
							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
						</DoubleAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
				<VisualState x:Name="ProxyStoppedState"/>
			</VisualStateGroup>
		</VisualStateManager.VisualStateGroups>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition/>
		</Grid.RowDefinitions>
		<i:Interaction.Triggers>
			<i:EventTrigger>
				<ic:ControlStoryboardAction Storyboard="{StaticResource LoadedStoryboard}"/>
			</i:EventTrigger>
		</i:Interaction.Triggers>
		<Grid x:Name="ConfigPanel" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="240" Margin="15,0">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition/>
			</Grid.ColumnDefinitions>
			<Grid.RenderTransform>
				<TransformGroup>
					<ScaleTransform/>
					<SkewTransform/>
					<RotateTransform/>
					<TranslateTransform/>
				</TransformGroup>
			</Grid.RenderTransform>
			<StackPanel Orientation="Vertical" Width="160">
				<Label Content="Local port" Style="{DynamicResource SimpleLabel}" Height="30" VerticalContentAlignment="Center"/>
				<Label Content="Access Key" Style="{DynamicResource SimpleLabel}" Height="30" VerticalContentAlignment="Center"/>
				<Label Content="Http script url" Style="{DynamicResource SimpleLabel}" Height="30" VerticalContentAlignment="Center"/>
				<Label Content="Https main script url" Style="{DynamicResource SimpleLabel}" Height="30" VerticalContentAlignment="Center"/>
				<Label Content="Https running script url" Style="{DynamicResource SimpleLabel}" Height="30" VerticalContentAlignment="Center"/>
				<Label Content="Https start script Url" Style="{DynamicResource SimpleLabel}" Height="30" VerticalContentAlignment="Center"/>
				<Label Content="Additional proxy" Style="{DynamicResource SimpleLabel}"  Height="30" VerticalContentAlignment="Center"/>
				<Label Content="Max running scripts" Style="{DynamicResource SimpleLabel}" Height="30" VerticalContentAlignment="Center" />
			</StackPanel>
			<StackPanel Grid.Column="1" DataContext="{Binding CurrentConfig}">
				<StackPanel Margin="0,6,0,0" Orientation="Horizontal">
					<TextBox Style="{DynamicResource SimpleTextBox}" Width="80" Text="{Binding LocalListenPort}" ToolTip="If the value is set to 0, an available port will be assigned automatically"/>
					<Label Content="1024~65536" Style="{DynamicResource SimpleLabel}" VerticalAlignment="Center" Margin="5,0,0,0"/>
				</StackPanel>
				<TextBox Style="{DynamicResource SimpleTextBox}" Width="200" Margin="0,6,0,0" HorizontalAlignment="Left" Text="{Binding AccessKey}"/>
				<TextBox Style="{DynamicResource SimpleTextBox}" Margin="0,6,0,0" Text="{Binding HttpUrl}"/>
				<TextBox Style="{DynamicResource SimpleTextBox}" Margin="0,6,0,0" Text="{Binding HttpsMainUrl}"/>
				<TextBox Style="{DynamicResource SimpleTextBox}" Margin="0,6,0,0" Text="{Binding HttpsRunningUrl}"/>
				<TextBox Style="{DynamicResource SimpleTextBox}" Margin="0,6,0,0" Text="{Binding HttpsStartUrl}"/>
				<StackPanel Orientation="Horizontal" Margin="0,6,0,0">
					<TextBox Style="{DynamicResource SimpleTextBox}" Width="170" Text="{Binding Proxy, Converter={StaticResource WebproxyToStringConverter}}" ToolTip="Keep empty if no proxy is used"/>
					<Label Content="The format of the address is host:port" Style="{DynamicResource SimpleLabel}" VerticalAlignment="Center" Margin="5,0,0,0"/>
				</StackPanel>
				<StackPanel Orientation="Horizontal" Margin="0,6,0,0">
					<TextBox Style="{DynamicResource SimpleTextBox}" Text="{Binding HttpsMaxRunnings}" Width="80" ToolTip="The recommended value is between 3 to 6"/>
					<Label Content="The value should be greater than 0" Style="{DynamicResource SimpleLabel}" VerticalAlignment="Center" Margin="5,0,0,0"/>
				</StackPanel>
			</StackPanel>
		</Grid>
		
		<Grid Grid.Row="1">
			<Button x:Name="StartButton" Content="Start" Style="{DynamicResource SimpleButton}" Width="150" HorizontalAlignment="Center" Height="25" VerticalAlignment="Center">
				<i:Interaction.Triggers>
					<i:EventTrigger EventName="Click">
						<ic:CallMethodAction MethodName="ChangeProxyState" TargetObject="{Binding Mode=OneWay}"/>
					</i:EventTrigger>
				</i:Interaction.Triggers>
			</Button>
			<StackPanel x:Name="InfoPanel" Orientation="Horizontal" Margin="15,0,0,0" Opacity="0">
				<Label Content="Local proxy address 127.0.0.1:" Style="{DynamicResource SimpleLabel}"/>
				<Label Content="{Binding CurrentConfig.LocalListenPort}" Style="{DynamicResource SimpleLabel}"/>
			</StackPanel>
		</Grid>
	</Grid>
</UserControl>